package st.business.tepth.business.taskallocation.returnfactory.content;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.CommonBean;

/**
 * @author zhangyu
 * @date 2019/9/3
 */
public class RepairAdapter extends BaseQuickAdapter<CommonBean, BaseViewHolder> {
    private List<CommonBean> mCheckList = new ArrayList<>();

    public RepairAdapter(int layoutResId, @Nullable List<CommonBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final CommonBean item) {
        LinearLayout layoutCheckLv = helper.getView(R.id.layout_check);
        final CheckBox checkBoxLv = helper.getView(R.id.check_box);
        checkBoxLv.setChecked(item.isSelected());
        layoutCheckLv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelected(!item.isSelected());
                if (item.isSelected()) {
                    mCheckList.add(item);
                    checkBoxLv.setChecked(true);
                } else {
                    mCheckList.remove(item);
                    checkBoxLv.setChecked(false);
                }
            }
        });
        helper.setText(R.id.tv_content, item.getName());
        helper.setVisible(R.id.iv_goto, false);
        helper.setVisible(R.id.tv_cancel_work, false);
    }
}
